// 存续管理页面
import React from 'react';
import { ContentPackage } from '../../../comps';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import TradeAddC from './tradeAdd';
import ManageTab from '../SurvivalManage';
import _ from 'lodash';

@Form.create()
class SurvivalManageNew extends React.Component {
  state = {
    pageStatus: 1, //显示列表页 还是交易录入
    listId: undefined, //当前系列产品id
  };
  componentDidMount() {}

  // 点击交易录入
  tradeAdd = () => {
    this.setState({ pageStatus: 2 });
  };

  // 刷新
  refresh = () => {
    //交易成功之后切换到主页面 并刷新页面
    this.setState({ pageStatus: 1 });
    this.ManageTab.refresh();
  };

  render() {
    let { pageStatus, listId } = this.state;
    return (
      <ContentPackage
        title='存续管理'
        contentHtml={
          <div>
            <div style={{ display: pageStatus == 1 ? 'block' : 'none' }}>
              <ManageTab
                tradeAdd={this.tradeAdd}
                getListId={(e) => {
                  this.setState({ listId: e });
                }}
                onRef={(ref) => (this.ManageTab = ref)}
              />
            </div>
            {pageStatus == 2 && (
              <div>
                <TradeAddC listId={listId} onClose={() => this.setState({ pageStatus: 1 })} onRefresh={this.refresh} />
              </div>
            )}
          </div>
        }
      />
    );
  }
}

export default SurvivalManageNew;
